#include<iostream>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int a[N], b[N];
int n;
int main()
{
	cin >> n;
	bool flag = 0;
	LL sum1 = 0, sum2 = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum1 += a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
		sum2 += b[i];
		if (b[i] != a[i])flag = 1;
	}
	if (!flag) {
		cout << "0" << endl;
		return 0;
	}
	if (sum1 != sum2) {
		cout << "-1" << endl;
		return 0;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += abs(a[i] - b[i]);
	}
	cout << ans / 2 << endl;
	return 0;
}